package cn.edu.zzuli.mapper;

import cn.edu.zzuli.entity.UserEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserEntityMapper {

    @Results(
            id = "users",
            value = {
                @Result(property = "likeCount", column = "like_count"),
                @Result(property = "cardCount", column = "card_count"),
                @Result(property = "followCount", column = "like_count"),
                @Result(property = "fansCount", column = "fans_count")
            }
    )
    @Select("select * from users where username = #{username}")
    UserEntity getUserByUserName(String username);

    @Select("select phone from users")
    List<String> getPhonesInfo();

    @ResultMap("users")
    List<UserEntity> list();

    @Select("select * from users where uId = #{id}")
    @ResultMap("users")
    UserEntity getUserById(Integer id);

    @Insert("insert into `users`(username, password, phone, gender, " +
            "avater, nickname) " +
            "values(#{username}, #{password}, #{phone}, #{gender}, #{avater}, #{nickname})")
    @Options(useGeneratedKeys = true, keyProperty = "uId", keyColumn = "uId")
    boolean add(UserEntity userEntity);
}
